<?php

class picslider extends Module
{  
	public $_values='';
	function __construct()
	{
		$this->name = 'picslider';
		$this->tab = 'front_office_features';
		$this->version = '0.1';
		$this->author = 'pahninsd@gmail.com';

		parent::__construct(); // The parent construct is required for translations

		$this->page = basename(__FILE__, '.php');
		$this->displayName = $this->l('picslider');
		$this->description = $this->l('photo slider showcase in home page using jquery');
	}
	
	public function hookHeader()
	{
		Tools::addJS(($this->_path).'picslider.js');
		Tools::addCSS(($this->_path).'picslider.css', 'all');
	}

	function install()
	{
		if (!Configuration::updateValue('PICSLIDER_IMG_DIRR',_PS_MODULE_DIR.'/picslider/img') OR 
		    !Configuration::updateValue('PICSLIDER_IMG_WIDTHH', '5880px') OR
		    !Configuration::updateValue('PICSLIDER_IMG_HEIGHTH', '490px') OR   
			!parent::install() OR 
			!$this->registerHook('home') OR
			!$this->registerHook('header'))
			return false;
		return true;
	}
	
	public function uninstall()
	{
		if (!parent::uninstall() OR
			!Configuration::deleteByName('PICSLIDER_IMG_WIDTHH') OR
			!Configuration::deleteByName('PIC_SLIDER_IMG_HEIGHTH'))
			return false;
		return true;
	}

	/**
	* Returns module content
	*
	* @param array $params Parameters
	* @return string Content
	*/
	function hookLeftColumn($params)
	{
		return $this->display(__FILE__, 'picslider.tpl');
	}
	
	function hookHome($params)
	{
		global $smarty;
		$counter=0;
		
		
		
		$dir = Configuration::get('PICSLIDER_IMG_DIRR');
		// open specified directory
		$dirHandle = opendir($dir);
		$slider_imgs = array();
		while ($file = readdir($dirHandle)) {
			$counter++;
			if(!is_dir($file) && strpos($file, '.jpg')>0) {
				array_push($slider_imgs,$this->_path.'img/'.$file);
			}
		}
		closedir($dirHandle);

		$smarty->assign(array(
		'slider_imgs' => $slider_imgs,
		'picsdir' => Configuration::get('PICSLIDER_IMG_DIRR')));
				$smarty->assign('width' , Configuration::get('PICSLIDER_IMG_WIDTHH'));
				$smarty->assign('height' , Configuration::get('PICSLIDER_IMG_HEIGHTH'));

		return $this->display(__FILE__, 'picslider.tpl');
	}
	
	public function getContent()
	{
		
		$this->_values.="<form action='".Tools::safeOutput($_SERVER['REQUEST_URI'])."' method='post' enctype='multipart/form-data'>width:<input type='text' name='width'><br>
		height:<input type='text' name='height'><br><br>
		image:<input type='file' name='file1'><br>
		<input type='submit' value='submit' name='submit'></form>";
		echo $this->_values;
		if(Tools::isSubmit('submit')){
			$dir = Configuration::get('PICSLIDER_IMG_DIRR');
			Configuration::updateValue('PICSLIDER_IMG_WIDTHH', $_POST['width']);
			Configuration::updateValue('PICSLIDER_IMG_HEIGHTH', $_POST['height']);
			if(is_uploaded_file($_FILES['file1']['tmp_name'])){
				$fn=$_FILES['file1']['name'];
				if(move_uploaded_file($_FILES['file1']['tmp_name'],"c://xampp/htdocs/prestashop/modules/picslider/img/$fn"))
				echo "file moved";
				else
				echo "not moved";
			}
			else
			echo "not uploaded";
		}
	}
}

?>
